<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>按符号重排数组</title>
</head>
<body>
  <script>
    function fn(nums) {
      let arr = []
      let count = []
      for (let num of nums) {
        if (num > 0) arr.push(num)
        else count.push(num)
      }
      let len = arr.length
      let res = []
      for (let i = 0; i < len; i++) {
        res.push(arr[i])
        res.push(count[i])
      }
      return res
    }
    console.log(fn([-1, 1]))
  </script>
</body>
</html>